package com.ccjq.jq173.order.service.impl;

import com.ccjq.jq173.core.util.PageUtils;
import com.ccjq.jq173.order.dao.OrderDao;
import com.ccjq.jq173.order.dao.impl.OrderDaoImpl;
import com.ccjq.jq173.order.po.Order;
import com.ccjq.jq173.order.po.PageInfo;
import com.ccjq.jq173.order.service.OrderService;

import java.util.List;

public class OrderServiceImpl implements OrderService {

    @Override
    public PageInfo<Order> queryOrders(String userId, int pageSize, int pageNo) {
        OrderDao o = new OrderDaoImpl();
        int startRow = PageUtils.getStartRow4Oracle(pageSize, pageNo);
        int endRow = pageSize * pageNo;
        int total = o.getCount(userId);
        int pages = PageUtils.getPageCount(total, pageSize);
        List<Order> orders = o.queryOrders(userId, startRow, endRow);

        PageInfo<Order> pageInfo = new PageInfo<Order>();
        pageInfo.setPageNo(pageNo);
        pageInfo.setTotal(total);
        pageInfo.setPages(pages);
        pageInfo.setPageSize(pageSize);
        pageInfo.setObjs(orders);
        return pageInfo;
    }

    @Override
    public Order getOrderDetail(String orderId) {
        OrderDao orderDao = new OrderDaoImpl();
        return orderDao.getOrderDetail(orderId);
    }
}
